//<template>
  <div>
      <p>产品名：<input type="text" v-model="name"></p>
      <p>价格：<input type="text" v-model="price"></p>
      <p>产品图片：<input type="file" id="img"></p>
      <p><select v-model="cate">
          <option v-for="i in a" :key="i.id" :value="i.id">{{i.name}}</option>
      </select></p>
      <p><input type="button" value="添加" @click="add()"></p>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            name:'',
            price:'',
            cate:'1',
            a:[]
        }
    },methods:{
        get(){
            axios({
                url:'http://127.0.0.1:8000/app02/categet/',
                method:'get',
            }).then(res=>{
                    this.a = res.data
            })
        },
        add(){
            let img = document.getElementById('img').files[0]
            let form_data = new FormData()
            form_data.append('name',this.name)
            form_data.append('price',this.price)
            form_data.append('img',img)
            form_data.append('cate',this.cate)
            axios({
                url:'http://127.0.0.1:8000/app02/proad/',
                method:'post',
                data:form_data
            }).then(res=>{
                console.log(res.data)
            })
        }
    },
    created(){
        this.get()
    }
}
</script>

<style>

</style>